<?php
namespace App\Libraries\Decorator\Tool;


use App\Libraries\Decorator\DecoratorInterface\ModelDecorator;

class IsFavDecorator implements ModelDecorator
{

    public function before(){
        //todo
    }

    public function after(&$data){
        if(!is_array($data)){
            $data = json_decode(json_encode($data), true);
        }
        if (!empty($data['id']) && empty($data['fav'])) {
            $data['fav'] = 0;
        } elseif(!empty($data['id']) && !empty($data['fav'])){
            if($data['fav']['status']){
                $data['fav'] = 1;
            }else{
                $data['fav'] = 0;
            }
        }else {
            // 多维数组
            if(is_array($data)){
                foreach($data as &$v){
                    $this->after($v);
                }
            }
        }
        return $data;
    }
}